<response>
	<token><?php echo $token; ?></token>
	<question>
		<id><?php echo $question['Question']['id']; ?></id>
		<name><?php echo $question['Question']['name']; ?></name>
		<action><?php echo $question['Question']['action']; ?></action>
		<incorrect_answer_helper><?php echo $question['Question']['incorrect_answer_helper']; ?></incorrect_answer_helper>
		<required_correct><?php if ($question['Question']['required_correct'] == 1){echo 'true';}else{echo 'false';} ?></required_correct>
		<question_text><?php echo $question['Question']['question']; ?></question_text>
		<answers>
<?php

	$correct_index = array();
	$correct_id = array();
	$incorrect_index = array();
	$incorrect_id = array();

	$count = 0;

	foreach ($question['Answer'] as $answer){
		
		// push the correct answer onto the correct answer array
		if ($answer['correct'] == 1)
		{
			$correct_index[] = $count;
			$correct_id[] = $answer['id'];
		}
		else if ($answer['correct'] == 0)
		{
			$incorrect_index[] = $count;
			$incorrect_id[] = $answer['id'];
		}
		
		$answer_display = $answer['answer_'.$question['Answervalue']['variable_type']].' '.$question['Answervalue']['abbreviation'];
		echo '<answer_'.$count.'>'.$answer_display.'</answer_'.$count.'>'."\n";
		
		$count ++;

	}
?>
		</answers>
		<count><?php echo $count;?></count>
		<correct_index_list>
<?php 

	$correct_index_count = 0;

	foreach ($correct_index as $correct_index_id){
?>
			<correct_index_<?php echo $correct_index_count;?>><?php echo $correct_index_id;?></correct_index_<?php echo $correct_index_count;?>>
<?php
		$correct_index_count ++;		
	}
?>
		</correct_index_list>
		<correct_id_list>
<?php 

	$correct_id_count = 0;

	foreach ($correct_id as $correct_id_id){
?>
			<correct_id_<?php echo $correct_id_count;?>><?php echo $correct_id_id;?></correct_id_<?php echo $correct_id_count;?>>
<?php

		$correct_id_count ++;

	}
?>
		</correct_id_list>
		<correct_count><?php echo count($correct_index);?></correct_count>
		<?php//incorrect data?>
		<count><?php echo $count;?></count>
		<incorrect_index_list>
<?php 

	$incorrect_index_count = 0;

	foreach ($incorrect_index as $incorrect_index_id){
?>
			<incorrect_index_<?php echo $incorrect_index_count;?>><?php echo $incorrect_index_id;?></incorrect_index_<?php echo $incorrect_index_count;?>>
<?php
		$incorrect_index_count ++;		
	}
?>
		</incorrect_index_list>
		<incorrect_id_list>
<?php 

	$incorrect_id_count = 0;

	foreach ($incorrect_id as $incorrect_id_id){
?>
			<incorrect_id_<?php echo $incorrect_id_count;?>><?php echo $incorrect_id_id;?></incorrect_id_<?php echo $incorrect_id_count;?>>
<?php

		$incorrect_id_count ++;

	}
?>
		</incorrect_id_list>
		<incorrect_count><?php echo count($incorrect_index);?></incorrect_count>
	</question>
</response>
